package com.sk.bilibili.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sk.bilibili.bean.Dynamic;
import com.sk.bilibili.dto.DynamicInfo;
import com.sk.bilibili.other.R;
import com.sk.bilibili.service.DynamicService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 邵康
 * @date 2021/11/24 11:44
 */
@CrossOrigin
@RestController
@RequestMapping("/dynamic")
@Api(tags = "动态")
public class DynamicController {

    @Autowired
    private DynamicService dynamicService;

    @ApiOperation("add")
    @PostMapping("/add")
    public R<Void> add(@RequestBody Dynamic dynamic) {
        return dynamicService.add(dynamic);
    }

    @ApiOperation("根据Id删除动态  只有图文转发动态可以删除")
    @GetMapping("/delete")
    public R<Void> delete(Integer id) {
        return dynamicService.delete(id);
    }

    @ApiOperation("update")
    @PostMapping("/update")
    public R<Void> update(@RequestBody Dynamic dynamic) {
        return dynamicService.update(dynamic);
    }

    @ApiOperation("page")
    @GetMapping("/page")
    public R<IPage<Dynamic>> page(@RequestParam(defaultValue = "1") Integer page,
                                  @RequestParam(defaultValue = "10") Integer size) {
        return dynamicService.page(page, size);
    }

    @ApiOperation("获取视频动态，可以分页 ")
    @PostMapping("/getDynamic")
    public R<IPage<Dynamic>> getDynamic(@RequestBody DynamicInfo dynamicInfo) {
        return dynamicService.getDynamic(dynamicInfo);
    }

    @ApiOperation("获取某个人的动态  不包含 置顶动态")
    @PostMapping("/getMemberDynamic")
    public R<IPage<Dynamic>> getMemberDynamic(@RequestBody DynamicInfo dynamicInfo) {
        return dynamicService.getMemberDynamic(dynamicInfo);
    }

    @ApiOperation("根据关键字搜索动态")
    @PostMapping("/pageSearch")
    public R<IPage<Dynamic>> pageSearch(@RequestBody DynamicInfo dynamicInfo) {
        return dynamicService.pageSearch(dynamicInfo);
    }

    @ApiOperation("获取热门动态 即  按点赞数  排序 不会有番剧更新动态")
    @GetMapping("/getHotDynamic")
    public R<IPage<Dynamic>> getHotDynamic(@RequestParam(defaultValue = "1") Integer page,
                                           @RequestParam(defaultValue = "10") Integer size) {
        return dynamicService.getHotDynamic(page, size);
    }

}
